package com.example.ormsqlsplicingframe1.orm.registry;

import com.example.ormsqlsplicingframe1.utlis.GetGenerics;
import com.example.ormsqlsplicingframe1.utlis.ObjValue;
import lombok.val;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class RegistryList implements Registry<List,String>{

    @Override
    public List decode(String value, Field field) {

        if (ObjValue.isNotNull(value) && field.getType() == List.class){

            val objects = new ArrayList<>(value.split(",").length);

            val generate = GetGenerics.getListGenerate(field);

            for (String s : value.split(",")) {
                objects.add(GetGenerics.typeReturn(generate,s));
            }

            return objects;
        }

        if (field.getType() == List.class){
            return new ArrayList();
        }

        return null;
    }



    @Override
    public Class<List> getObj() {
        return List.class;
    }
}
